<!DOCTYPE html>

<html>

	<head>
		<meta charset="utf-8">
		<title>忘记密码 - 立刷伙伴</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
		<link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
		<link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
		<link rel="stylesheet" href="../../layuiadmin/style/login.css" media="all">
	</head>

	<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display: none;">
		<div class="layadmin-user-login-main">
			<div class="layadmin-user-login-box layadmin-user-login-header">
				<h2>立刷伙伴</h2>
				<!-- <p>layui 官方出品的单页面后台管理模板系统</p> -->
			</div>
			<div class="layadmin-user-login-box layadmin-user-login-body layui-form">

				<script type="text/html" template>
					{{# if(layui.router().search.type === 'resetpass'){ }}
					<div class="layui-form-item">
						<label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-password"></label>
						<input type="password" name="password" id="LAY-user-login-password" lay-verify="pass" placeholder="新密码" class="layui-input">
					</div>
					<div class="layui-form-item">
						<label class="layadmin-user-login-icon layui-icon layui-icon-password" for="LAY-user-login-repass"></label>
						<input type="password" name="repass" id="LAY-user-login-repass" lay-verify="required" placeholder="确认密码" class="layui-input">
					</div>
					<div class="layui-form-item">
						<button class="layui-btn layui-btn-fluid" lay-submit lay-filter="LAY-user-forget-resetpass">重置新密码</button>
					</div>
					{{# } else { }}
					<div class="layui-form-item">
						<label class="layadmin-user-login-icon layui-icon layui-icon-cellphone" for="LAY-user-login-cellphone"></label>
						<input type="text" name="mobile" lay-verify="phone" placeholder="请输入注册时的手机号" class="layui-input">
					</div>
					<div class="layui-form-item">
						<div class="layui-row">
							<div class="layui-col-xs7">
								<label class="layadmin-user-login-icon layui-icon layui-icon-vercode"></label>
								<input type="text" name="smscode" lay-verify="required" placeholder="短信验证码" class="layui-input">
							</div>
							<div class="layui-col-xs5">
								<div style="margin-left: 10px;">
									<button type="button" class="layui-btn layui-btn-primary layui-btn-fluid" id="getsmscode">获取验证码</button>
								</div>
							</div>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layadmin-user-login-icon layui-icon layui-icon-password"></label>
						<input type="password" name="code" lay-verify="required" placeholder="设置密码" class="layui-input">
					</div>
					<div class="layui-form-item">
						<button class="layui-btn layui-btn-fluid" lay-submit lay-filter="forget-submit">找回密码</button>
					</div>
					{{# } }}
				</script>
			</div>
		</div>
	</div>

	<script src="../../layuiadmin/layui/layui.js"></script>
	<script src="../../js/common.js"></script>
	<script>
		layui.config({
			base: '../../layuiadmin/' //静态资源所在路径
		}).extend({
			index: 'lib/index' //主入口模块
		}).use(['index', 'user'], function() {
			var $ = layui.$,
				setter = layui.setter,
				admin = layui.admin,
				form = layui.form,
				router = layui.router();
			form.render();


			var countdown = 60;
			var _generate_code = $("#getsmscode");

			function settime() {
				if (countdown == 0) {
					_generate_code.attr("disabled", false);
					_generate_code.removeClass("layui-btn-disabled");
					_generate_code.html("获取验证码");
					countdown = 60;
					return false;
				} else {
					_generate_code.attr("disabled", true);
					_generate_code.addClass("layui-btn-disabled");
					_generate_code.html("重新发送(" + countdown + ")");
					countdown--;
				}
				setTimeout(function() {
					settime();
				}, 1000);
			}

			$('#getsmscode').on('click', function() {
				var mobile = $('input[name=mobile]').val();
				if (!mobile) {
					layer.msg('请输入电话号码');
				} else if (!telReg.test(mobile)) {
					layer.msg('请输入正确的电话号码');
				} else {
					$.get(server.queryusersmscode, {mobile: mobile}, function(res, status) {
						if (status == 'success') {
							if (res.code == 0) {
							} else {
								layer.msg(res.msg);
							}
							closeloading();
						} else {
							closeloading();
							layer.msg('服务器连接错误');
						}
					});
					 settime();  
				}
			})

			//找回密码下一步
			form.on('submit(forget-submit)', function(obj) {
				var field = obj.field;
				console.log(field);

				submitdata(server.forget_updatepassword,field)

				return false;
			});


			//重置密码
			form.on('submit(LAY-user-forget-resetpass)', function(obj) {
				var field = obj.field;

				//确认密码
				if (field.password !== field.repass) {
					return layer.msg('两次密码输入不一致');
				}
				return false;
			});

			function submitdata(_url,_data) {
				$.post(_url, _data, function(res, status) {
					if (status == 'success') {
						if (res.code == 0) {
							layer.alert('操作成功', function() {
								location = '../login.html'
							});
						} else {
							layer.msg(res.msg);
						}
						closeloading();
					} else {
						closeloading();
						layer.msg('服务器连接错误');
					}
				});
			}

		});
	</script>
	</body>

</html>